package com.xmz.controller;

import com.xmz.entity.SClass;
import com.xmz.entity.Student;
import com.xmz.service.StudentService;
import com.xmz.util.PageResult;
import com.xmz.util.Result;
import com.xmz.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
@CrossOrigin
public class StudentController {
    @Autowired
    private StudentService studentService;
    @PostMapping("/loadList")
    public PageResult<Student> loadList(Integer pageNo, Integer pageSize, @RequestBody StudentVo searchStudent){
        return  studentService.loadList(pageNo,pageSize,searchStudent);
    }
    @GetMapping("/loadAllClass")
    public List<SClass> loadAllClass(){
        return  studentService.loadAllClass();
    }
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Student student){
        int i = studentService.addStudent(student);
        if(i > 0) return Result.success("添加成功！");
        return Result.error("添加失败！");
    }

    @DeleteMapping("/deleteStudent")
    public Result deleteStudent(Integer id){
        int i = studentService.deleteStudent(id);
        if(i > 0) return Result.success("删除成功！");
        return Result.error("删除失败！");
    }
    @PutMapping("/updateStudent")
    public com.xmz.util.Result updateStudent(@RequestBody com.xmz.entity.Student student){
        int i = studentService.updateStudent(student);
        if(i > 0) return com.xmz.util.Result.success("修改成功！");
        return com.xmz.util.Result.error("修改失败！");
    }

}
